Algorithmic Thinking for Adventurous Minds: Quest for Fundamental Algorithms with Visualization and Python by Xu Claire & Xu Raymond & Xu William
Author:Xu, Claire & Xu, Raymond & Xu, William [Xu, Claire]
Language: eng
Format: epub
Published: 2021-04-26T00:00:00+00:00
Table 2.10
Coin Change Problem: coupon values and total amount to change
âWeâre in the academy.â the store owner says, âas our customer, you shall prove your intelligence by using the least number of coupons for your purchase.â
At the speed of light, Banana Split sorts through the coupons and picks the higher face values by order: one $6 and four $1 coupons.
âWait! Letâs double check⦠well⦠two $5 coupons are clearly better.â Dark Knight states, as he does his due diligence.
âBut how come our greedy approach worked just fine when selling the CalliLens in Greedy-ent Mart?!?â Bubble Gum asks, surprised.
Pause here. Can you spot the difference between the two problems?
âHmm...letâs carefully examine the two sets of face values,â Banana Split reminds the group, âthe US bill system has $1, $5, $10, $20, $50, and $100. Whereas the store coupons have $1, $5, and $6.â
Which set of numbers works for Greedy and which doesnât?
Answer:
In cases where there is a bill whose value ($6) is added to the smallest bill ($1), is lower than twice that of the bill immediately less than it ($5), the Greedy approach will not work. In this case, $6 + $1 < 2 x $5. Thatâs why!
âWow, thatâs eye-opening!â Banana Split exclaims intrigued, âthis is an optimization problem. If we cannot go with Greedy, letâs try it with DP! Does this problem have the two DP properties?â
They peer through CalliLens together.
If we have an unlimited number for each bill type S[]=[S1, S2, Sm], whatâs the solution to select the least number of bills to pay price N. Use a function to represent the solution: f(N).
In our case, S[]=[$1, $5, $6], N = 10
Optimal Substructure
Let Sj be the last bill added to the optimal solution. So the total number of bills is 1 (last bill) + the number of bills to make up
N-Sj: f(N) = 1 + f(N-Sj)
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
API Testing and Development with Postman by Dave Westerveld(3618)
Learning C# by Developing Games with Unity 2020 by Harrison Ferrone(2615)
Software Architecture for Busy Developers by Stéphane Eyskens(2322)
2021 Beginners Guide to Python Programming Language: A Crash Course to Mastering Python in One Hour by Elmer Gary & Elmer Gary(1884)
Machine Learning for Algorithmic Trading by Stefan Jansen(1628)
Hands-On ROS for Robotics Programming by Bernardo Ronquillo Japón(1572)
Delphi GUI Programming with FireMonkey by Andrea Magni(1457)
Game Development Projects with Unreal Engine by Hammad Fozi & Goncalo Marques & David Pereira & Devin Sherry(1402)
Cloud Native with Kubernetes by Alexander Raul(1374)
Datadog Cloud Monitoring Quick Start Guide by Thomas Kurian Theakanath(1346)
Software Architecture Patterns for Serverless Systems by John Gilbert(1338)
Practical Node-RED Programming by Taiji Hagino(1336)
Automate It with Zapier by Kelly Goss(1318)
Practical System Programming for Rust Developers by Prabhu Eshwarla(1312)
Delphi Programming Projects by William Duarte(1296)
Mastering React Test-Driven Development by Daniel Irvine(1290)
Developing Multi-Platform Apps with Visual Studio Code by Ovais Mehboob Ahmed Khan & Khusro Habib & Chris Dias(1253)
Ghidra Software Reverse Engineering for Beginners by A. P. David(1244)
Learn Spring for Android Application Development by S. M. Mohi Us Sunnat(1235)
